# import sqlite3
# from itertools import islice
# import jieba
#
#
# class ArticleDB(object):
#     con = sqlite3.connect("data.db")
#
#     def InsertEntity(self, url, title, author, university, year, level, specialty, aritcle_id):
#         cur = self.con.cursor()
#         cur.execute(f"select * from aritcle where aritcle.aritcle_id = '{aritcle_id}'")
#         if len(cur.fetchall()) == 0:
#             insert_sql = f'INSERT INTO aritcle (`url`,`title`,`author`,`university`,`year`,`level`,`specialty`,`aritcle_id`) VALUES ("{url}","{title}","{author}","{university}","{year}","{level}","{specialty}","{aritcle_id}")'
#             cur.execute(insert_sql)
#         self.con.commit()
#
#     def GetKeyWords(self):
#         cur = self.con.cursor()
#         cur.execute(f"select * from aritcle order by id desc")
#         for item in cur.fetchall():
#             title = item[2]
#             words = jieba.lcut(title)
#             for word in words:
#                 if len(word) > 1:
#                     cur.execute(f"select * from keywords where keywords.key = '{word}'")
#                     if len(cur.fetchall()) == 0:
#                         insert_sql = f"INSERT INTO keywords (`key`) VALUES ('{word}')"
#                         cur.execute(insert_sql)
#             self.con.commit()
#
#     def DownloadUrl(self):
#         cur = self.con.cursor()
#         cur.execute(f"select * from aritcle where aritcle.status = 0 order by id limit 1")
#         article = cur.fetchone()
#         return article
#
#     def UpdateAritcleStatus(self, aritcle_id, status, local_url):
#         cur = self.con.cursor()
#         cur.execute(f"update aritcle set status={status},local_url='{local_url}' where aritcle_id='{aritcle_id}'")
#         self.con.commit()
#
#
# if __name__ == '__main__':
#     db = ArticleDB()
#     # db.InsertEntity('http://d.cn-ki.net/idata_down?filename=QlUU4onRlJ0KsdFcxR2SrQXRxQjUzBDcSVWWOh0Mtt0M0VET5AXVwJWZmxkZwlnTa5WSv02Yll2a1lnQvVHR0JmWCNjTzREcKJ0TDp1YVlmZLJWbpxkShh3Qv4Gdy40TrxGZxJ2drpFVMdjVXxEaWtERZdlQMNke&tablename=CDFDLAST2015&filename_ex=1015589361.nh&cnname=物联网产业发展的理论分析与对策研究&author=苏美文,','物联网产业发展的理论分析与对策研究', '苏美文', '吉林大学','2015年', '博士','西方经济学')
#     db.GetKeyWords()
